package com.zx.article.writer.service.impl;

import java.util.List;

import com.zx.article.util.FmtRequest;
import com.zx.article.writer.dao.IWriterDao;
import com.zx.article.writer.dao.impl.WriterDaoImpl;
import com.zx.article.writer.model.WriterModel;
import com.zx.article.writer.service.IWriterService;

public class WriterServiceImpl implements IWriterService {

	private IWriterDao writerDao = new WriterDaoImpl();

	@Override
	public List<WriterModel> get(WriterModel writerModel) {
//		writerModel.setAccount(writerModel.getAccount() == null ? null : "%" + writerModel.getAccount() + "%");
//		writerModel.setPenName(writerModel.getPenName() == null ? null : "%" + writerModel.getPenName() + "%");
//		writerModel.setRealName(writerModel.getRealName() == null ? null : "%" + writerModel.getRealName() + "%");
		return writerDao.queryList(writerModel);
	}

	@Override
	public String del(String account) {
		return "1".equals(writerDao.deleteModel(account)) ? "success" : "fail";
	}

	@Override
	public String add(WriterModel writerModel) {
		return "1".equals(writerDao.insertModel(writerModel)) ? "success" : "fail";
	}

	@Override
	public String updata(WriterModel writerModel) {
		return "1".equals(writerDao.updataModel(writerModel)) ? "success" : "fail";
	}

	@Override
	public String reset(WriterModel writerModel) {
		writerModel.setPassword(new FmtRequest().encode("123"));
		return "1".equals(writerDao.updataModel(writerModel)) ? "success" : "fail";
	}

	@Override
	public WriterModel getModel(String account) {
		return writerDao.querModel(account);
	}

	@Override
	public int getCount(WriterModel writerModel) {
		writerModel.setAccount(writerModel.getAccount() == null ? null : "%" + writerModel.getAccount() + "%");
		writerModel.setPenName(writerModel.getPenName() == null ? null : "%" + writerModel.getPenName() + "%");
		writerModel.setRealName(writerModel.getRealName() == null ? null : "%" + writerModel.getRealName() + "%");
		return writerDao.queryCount(writerModel);
	}

	@Override
	public List<WriterModel> getAll() {
		return writerDao.queryList(new WriterModel());
	}

}
